import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/ui/cooperation/activity/publish/act_publish_page.dart';
import 'package:fate_blind_box/utils/common_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../network/Api.dart';
import '../../../utils/provider.dart';
import 'my_act_list_controller.dart';
import 'my_act_list_page.dart';

class MyActTabPage extends StatefulWidget {
  const MyActTabPage({Key? key}) : super(key: key);

  @override
  State<MyActTabPage> createState() => _MyActTabPageState();
}

class _MyActTabPageState extends State<MyActTabPage>
    with SingleTickerProviderStateMixin {
  late TabController importTabController;
  List<String> tabList = ['我发起的', '我参与的', '已过期的'];
  double tabFontSize = 16.0;
  MyActListController mainController = Get.put(MyActListController());

  double px = 1.sw - 25 - 92;
  double py = 1.sh -
      62 -
      92 -
      ScreenUtil().bottomBarHeight -
      ScreenUtil().statusBarHeight;

  @override
  Widget build(BuildContext context) {
    return AppWidget.navTitleBar(
      bgColor: ThemeColor.sendMsgColor,
      appBarColor: ThemeColor.sendMsgColor,
      title: '我的活动',
      childWidget: Stack(
        children: [
          Column(
            children: [
              SizedBox(
                height: 40,
                child: TabBar(
                  tabs: getTabList(),
                  controller: importTabController,
                  labelColor: ThemeColor.black3D3D3DColor,
                  unselectedLabelColor: ThemeColor.grayA0A0A0Color,
                  indicatorSize: TabBarIndicatorSize.label,
                  indicatorColor: ThemeColor.appColor,
                  unselectedLabelStyle: TextStyle(
                    fontSize: tabFontSize,
                  ),
                  // 未选择样式
                  labelStyle: TextStyle(
                      fontSize: tabFontSize,
                      fontWeight: FontWeight.w500), // 选择的样式
                ),
              ),
              Container(
                height: 0.5,
                color: ThemeColor.lineColor,
              ),
              Expanded(
                child: TabBarView(controller: importTabController, children: [
                  GetBuilder(
                      id: mainController.myPubViewId,
                      builder: (MyActListController controller) {
                        return  MyActListPage(
                          dataList: controller.pubList,
                          tabTitle: tabList.first,
                        );
                      }),
                  GetBuilder(
                      id: mainController.attendViewId,
                      builder: (MyActListController controller) {
                        return MyActListPage(
                          dataList: controller.attendList,
                          tabTitle: tabList[1],
                        );
                      }),
                  GetBuilder(
                      id: mainController.expireViewId,
                      builder: (MyActListController controller) {
                        return MyActListPage(
                          dataList: controller.expireList,
                          tabTitle: tabList.last,
                        );
                      }),
                ]),
              ),
            ],
          ),
          Positioned(
            top: py,
            left: px,
            width: 92,
            height: 92,
            child: GestureDetector(
                onPanUpdate: (details) {
                  setState(() {
                    px += details.delta.dx;
                    py += details.delta.dy;
                  });
                },
                onTap: (){
                  Get.to(const ActPublishPage());
                },
                child: Image.asset('images/map/my_act_add.png')),
          ),
        ],
      ),
    );
  }

  //组装tab
  List<Widget> getTabList() {
    List<Widget> list =
        List.generate(tabList.length, (index) => Tab(text: tabList[index]));
    return list;
  }

  @override
  void initState() {
    super.initState();
    importTabController = TabController(length: tabList.length, vsync: this);
    mainController.getMyPublishData();
    //获取好友列表成功后调用群列表后台加缓存
     Api.getInstance().getGroupList(Provider.userEaseName);
  }
}
